import { request } from '@/network/index'
// 获取用户数据列表
export function getUsersData(config) {
  return request(
    {
      url: 'users',
      method: 'get',
      params: {
        query: config.query,
        pagenum: config.pagenum,
        pagesize: config.pagesize
      }
    }
  )
}
// 修改用户状态
export function changeStatus(config) {
  return request(
    {
      url: `users/${config.id}/state/${config.mg_state}`,
      method: 'put'
    }
  )
}
// 添加用户
export function addUser(config) {
  return request(
    {
      url: 'users',
      method: 'post',
      data: {
        username: config.username,
        password: config.password,
        email: config.email,
        mobile: config.mobile
      }
    }
  )
}
// 根据 ID 查询用户信息
export function getUserDataById(id) {
  return request(
    {
      url: `users/${id}`,
      method: 'get'
    }
  )
}

// 编辑用户提交
export function editUserMessageById(config) {
  return request(
    {
      url: `users/${config.id}`,
      method: 'put',
      data: {
        email: config.email,
        mobile: config.mobile
      }
    }
  )
}

// 删除单个用户
export function deleteSingleUserMessage(id) {
  return request(
    {
      url: `users/${id}`,
      method: 'delete'
    }
  )
}

// 角色列表
export function getRoleList() {
  return request(
    {
      url: 'roles',
      method: 'get'
    }
  )
}

// 分配用户角色
export function setRole(id, rid) {
  return request(
    {
      url: `users/${id}/role`,
      method: 'put',
      data: {
        rid: rid
      }
    }
  )
}
